# 定义单例类来管理设备分辨率
import adbutils
from adbutils import WindowSize, AdbDevice


class DeviceResolutionManager:
    _instance = None
    _resolutions = {}

    def __new__(cls):
        if not cls._instance:
            cls._instance = super().__new__(cls)
        return cls._instance

    def get_resolution(self, device:  AdbDevice)->WindowSize:
        """
        获取设备分辨率
        """
        device_id = device.serial
        if device_id not in self._resolutions:
            wz = device.window_size()
            # 解析输出，例如 "Physical size: 1080x1920"
            try:
                self._resolutions[device_id] = wz
            except Exception:
                self._resolutions[device_id] = None
        return self._resolutions[device_id]

# 创建单例实例
resolution_manager = DeviceResolutionManager()